#ifndef _USER_AHT20_H
#define _USER_AHT20_H

#ifdef __cplusplus
extern "C" {
#endif

#include "stdint.h"


#include "stdint.h"
#include "driver/i2c.h"
#include "driver/gpio.h"
#include "esp_types.h"

#define i2c_master_port I2C_NUM_0
#define aht20_addr    0x38
#define ACK_CHECK_EN  0x1                       /*!< I2C master will check ack from slave*/
#define ACK_CHECK_DIS 0x0                       /*!< I2C master will not check ack from slave */
#define ACK_VAL  0x0                            /*!< I2C ack value */
#define NACK_VAL 0x1                            /*!< I2C nack value */


#if CONFIG_IDF_TARGET_ESP32
//#define AHT20_SCL_PIN 18
//#define AHT20_SDA_PIN 19
#define AHT20_SCL_PIN 32
#define AHT20_SDA_PIN 33
#elif CONFIG_IDF_TARGET_ESP32S3
#define AHT20_SCL_PIN 17
#define AHT20_SDA_PIN 18
#endif

// AHT20
typedef struct
{
    uint8_t valid;
    float   temp;
    float   humi;
}aht20_flag_t;

extern aht20_flag_t aht20_flag;

esp_err_t user_iic_init(void);
void check_calibration();
bool getbit(int NUM, int n);
esp_err_t trigger_measure(void);
void user_aht20_task(void *ignore);


#ifdef __cplusplus
} /* extern "C" */
#endif

#endif
